Skip to content

fix: Recover handler errors, turn into HTTP 500 response (port from akka-http PR #4242)#1017

Draft
pjfanning wants to merge 2 commits into
apache:mainfrom
pjfanning:copilot/copy-akka-http-pr-4242
Draft

fix: Recover handler errors, turn into HTTP 500 response (port from akka-http PR #4242)#1017
pjfanning wants to merge 2 commits into
apache:mainfrom
pjfanning:copilot/copy-akka-http-pr-4242

Conversation

@pjfanning
Copy link
Copy Markdown
Member

Port of akka/akka-http#4242 to Pekko HTTP.
Now Apache licensed. https://github.com/akka/akka-http/releases/tag/v10.5.1

References: akka/akka-http#4241

Summary

When an HTTP/2 handler throws an exception (either synchronously or by failing a Future), the server previously propagated that error in a way that could tear down the connection. This change wraps the user-provided handler to catch both synchronous and asynchronous errors, converting them into HTTP 500 Internal Server Error responses, keeping the connection alive for further requests.

Changes

  • Http2.scala: Added withErrorHandling method that wraps the user handler to recover from NonFatal exceptions (sync throws and Future failures), returning an HTTP 500 response and logging the error. The wrapped handler is used for both HTTP/1 upgrade handling and the HTTP/2 stream handler.
  • Http2HighlevelServerSpec.scala (new): Integration test verifying that when a handler fails, the server returns HTTP 500 and the connection remains usable for subsequent requests.

All imports and config keys updated from akka.* to pekko.* namespace.

@pjfanning pjfanning added this to the 2.0.0-M2 milestone Apr 18, 2026
@Philippus
Copy link
Copy Markdown
Member

Failing on this part of the spec:

            8.1.2.1. Pseudo-Header Fields
              1: Sends a HEADERS frame that contains a unknown pseudo-header field

@pjfanning pjfanning marked this pull request as draft April 19, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants